package flower
{
	//import com.flower.app.people.module.FairyAction;
	//import com.flower.core.GoodsInfo;
	//import com.flower.core.loading.LoaderList;
	//import com.flower.core.manager.UIManager;
	
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.net.URLRequest;
	
	public class Bone
	{
		private var arr:Array//穿在身上的衣服数组 
		private var startID:uint//骨骼开
		private var anmBool:Boolean//是否是场景飞行骨骼
		private var changeBoneBool:Boolean//是否是换骨骼
		private var bonetype:uint//骨骼1234
		private var bone:MovieClip//骨骼
		public var BC_List:Object
		private var url:String=Fairy.rooturl
		public function Bone(_bone:MovieClip,_type:uint,_anmbool:Boolean=false)
		{
			anmBool=_anmbool
			bonetype=_type//如果＝＝0没骨骼（骨骼放在内部，不用加载了）
			bone=_bone
			if(bonetype!=0){
				init()
			}
		}
		public static  function MakeBone(facecolor:uint,_x:uint,_y:uint,_scale:Number,_float:Boolean=true,bone:MovieClip = null,time:uint = 1,$armBool:Boolean = false):MovieClip
		{
			
			var tmpbone:MovieClip = new MovieClip();
			
				tmpbone = bone;
			
			
			tmpbone.x=_x
			tmpbone.y=_y
			tmpbone.scaleX=tmpbone.scaleY=_scale
			new Bone(tmpbone.ff.bone,facecolor,$armBool)
			
			return tmpbone
		}
		public function changebone():void
		{
			changeBoneBool=true
		}
		private function init():void
		{
			arr=new Array()
			startID=1400001+bonetype*7
			for(var i:uint=startID;i<startID+7;i++)
			{
				arr.push(i)
			}
			loadbone()
		}
		private function loadbone():void
		{
			loadcloth(url+"face/"+arr[0]+".swf",bone.head)
			loadcloth(url+"left/"+arr[1]+".swf",bone.lefthand)
			loadcloth(url+"right/"+arr[1]+".swf",bone.righthand)
			
			loadcloth(url+"left/"+arr[2]+".swf",bone.leftarm)
			loadcloth(url+"right/"+arr[2]+".swf",bone.rightarm)
			
			loadcloth(url+"body/"+arr[3]+".swf",bone.body)
			
			loadcloth(url+"body/"+arr[4]+".swf",bone.belly)
			
			loadcloth(url+"left/"+arr[5]+".swf",bone.leftleg)
			loadcloth(url+"right/"+arr[5]+".swf",bone.rightleg)
			
			loadcloth(url+"left/"+arr[6]+".swf",bone.leftfoot)
			loadcloth(url+"right/"+arr[6]+".swf",bone.rightfoot)
		}
		
		/**
		 * unLOAD CLOTH
		 * 
		 * */
		private function unloadcloth(mc:MovieClip):void
		{
			while(mc.numChildren>0){
				mc.removeChildAt(0)
			}
		}

		/**
		 * LOAD CLOTH
		 * 
		 * */
		private function loadcloth(url:String,mc:MovieClip,clothType:uint = 0):void
		{
			var tempLoader:Loader=new Loader()
			var tmc:MovieClip;
			if(anmBool){
				if(mc.getChildByName("type_"+clothType))
				{
					mc.removeChild(mc.getChildByName("type_"+clothType));
				}
				tmc = new MovieClip();
				tmc.addChild(tempLoader);
				tmc.name = "type_"+clothType;
				mc.addChildAt(tmc,1);
			}else{
				if(mc.getChildByName("type_"+clothType))
				{
					mc.removeChild(mc.getChildByName("type_"+clothType));
				}
				tmc = new MovieClip();
				tmc.addChild(tempLoader);
				tmc.name = "type_"+clothType;
				mc.addChildAt(tmc,0)
			}
			tempLoader.load(new URLRequest(url))
			
		//	try{LoaderList.getInstance().addItem(tempLoader,VL.getURLRequest(url),LoaderList.STANDARD,true);}catch(E:*){}
			//BC.addEvent(this,tempLoader.contentLoaderInfo,IOErrorEvent.IO_ERROR,clothloadIOError)
			//BC.addEvent(this,tempLoader.contentLoaderInfo,Event.INIT,clothloaded)
		}
		private function clothloadIOError(E:IOErrorEvent):void
		{
			trace(E)
			//BC.removeEvent(this,E.currentTarget)
		}
		private function clothloaded(E:Event):void
		{
			//BC.removeEvent(this,E.currentTarget)	
		}
	}
}